package kiwi.assist.dev.guieditor.model {
	import kiwi.assist.dev.util.SkinComponentAdapter;
	import kiwi.util.asserts.assert;

	import flash.display.DisplayObject;

	/**
	 * 整个gui的配置信息
	 * @author zhangming.luo
	 */
	public class GUIEditorConfig {
		public var styles : Vector.<StyleLibConfig> = new Vector.<StyleLibConfig>();
		public var uis : Vector.<UiConfig> = new Vector.<UiConfig>();
		public var containers : Vector.<ContainerConfig> = new Vector.<ContainerConfig>();
		public var defaultContainer : ContainerConfig;
		public var uiPrefix : String;

		/**
		 * 获取ui实例的
		 */
		public function getUiConfigByDos(dos : DisplayObject) : UiConfig {
			if (dos is SkinComponentAdapter) {
				// 背景
				return SkinComponentAdapter(dos).uiConfig;
			}
			for each (var uiConfig : UiConfig in uis) {
				if (uiConfig.instanceMap[dos]) {
					return uiConfig;
				}
			}
			assert(false, "没有找到对应的ui配置");
			return null;
		}

		/**
		 * 根据comp来获取对应的配置
		 */
		public function getUiConfigByComp(comp : String) : UiConfig {
			var result : UiConfig;
			uis.some(function(item : UiConfig, index : int, array : *) : Boolean {
				if (item.comp == comp) {
					// 需要覆盖了
					result = item;
					return true;
				}
				return false;
			});
			return result;
		}

		/**
		 * 获取皮肤
		 */
		public function getSkinByName(name : String) : SkinConfig {
			for each (var lib : StyleLibConfig in styles) {
				if (name in lib.skines) {
					return lib.skines[name];
				}
			}
			var config : SkinConfig = new SkinConfig(name);
			return config;
		}
	}
}
